package operation.map;

import java.util.HashMap;
import java.util.HashSet;

public class MapDemo03 {
    /*第二题和第三题有难度, 可以小组讨论下
2. 分析以下需求，并用代码实现：
	(1)统计每个单词出现的次数
	(2)有如下字符串"If you want to change your fate I think you must come to the dark horse to learn java"(用空格间隔)
	(3)打印格式：
		to=3
  		think=1
  		you=2*/
    public static void main(String[] args) {
        String s="If you want to change your fate I think you must come to the dark horse to learn java";
        String s1 = s.toLowerCase();
        String[] s2 = s1.split(" ");
        HashMap<String,Integer> hashMap=new HashMap<>();
        for (String s3 : s2) {
            int count=1;
            if (hashMap.containsKey(s3)) {
               count= hashMap.get(s3)+1;
            }
            hashMap.put(s3,count);
        }
        System.out.println(hashMap);


    }
}
